const db = wx.cloud.database({
  env: "treeworld-2g5yvz9s899bf4a6"
})
var util = require('../../utils/time.js');
const app = getApp()

Component({
  pageLifetimes: {
    show() {
      if (typeof this.getTabBar === 'function' &&
        this.getTabBar()) {
        this.getTabBar().setData({
          selected: 1
        })
      }
    }
  },
  properties: {
    popr: {
      type: Number,
      default: 0
    }, 
  },

  data: {
    tz_list: [],
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    Custom: app.globalData.Custom,

  },
  created() {
    this.list()


  },
  methods: {
    getQRCode: function(){
      var _this = this;
      wx.scanCode({        //扫描API
        success: function(res){
          console.log(res);    //输出回调信息
          _this.setData({
            qRCodeMsg: res.result
          });
          wx.showToast({
            title: '成功',
            duration: 2000
          })
        }
      })
    }
  ,
    list() {
      const a = db.command
      db.collection('press').limit(20).orderBy('browse', 'desc').orderBy('_createTime','asc').where({
        browse: a.gt(10)
      }).get().then(res => {
        this.setData({
          xw_list: res.data
        })
      })
   
        wx.cloud.callFunction({
          name: 'userlist',
        }).then(res => {
          this.setData({
            userlist: res.result.data
          })
   
        })
      db.collection('press').where({
        Top:true
      }).get().then(res => {

        this.setData({
          tz_list: res.data
        })
      })
      wx.cloud.callFunction({
        name: 'user_browse',
      }).then(res => {
       this.setData({
          t_data_rs:res.result.total+23
        })
      })
    },
    tz(e) {
      wx.navigateTo({
        url: "../../pages/" + e.currentTarget.dataset.a + "?id=" + e.currentTarget.dataset.id
      })
    },
  }
})